/*
SC
*/

#ifndef OTHERSCC_H_
#define OTHERSCC_H_
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;
		
class OtherSCC
{
public:
	
	static Customer cust;
	static string cust_name;
	static vector<Cart_item> items;
	static vector<Product> prods;
	static vector<Category> cats;
	static vector<Cart> carts;
	static vector<Customer> custs;
	static vector<Customer> a;
	
	//otherSCC(){}
	
	static void show(vector<Customer> custs)
	{		
		vector<Customer> alpha=custs;
		vector<string> names;
		
		for (int i=0 ; i<custs.size() ; ++i)
		{
			names.push_back(custs[i].cust_name);
		}
		
		sort(names.begin(),names.end());
			
		for (int i=0; i<custs.size() ; ++i)
		{
			for (int j=0; j<names.size() ; ++j)
			{
				if (custs[i].cust_name == names[j])
				{
					alpha[j] = custs[i];
				}
			}
		}
		
		for (int i=0 ; i<alpha.size() ; ++i)//repeats for each line //RY I changed a to custs for now
		{
			cout 	<< alpha[i].cust_name << " "
					<< '(' << alpha[i].cust_id << "): "
					<< alpha[i].addr.house << " "
					<< alpha[i].addr.street << " "
					<< alpha[i].addr.zip_code << endl;
		}	
		cout << endl;
	}
	
	static void delete_cart_item(vector<Cart> carts, vector<Customer> custs, vector<Product> prods, vector<Cart_item> *cart_items)
	{	
		vector<Cart> cust_carts;		//holds carts purchased by a customer that could possibly be edited
		vector<Cart_item> cust_items;	//holds possible items to be edited inside single cart
		
		int choice;
		int cust_id, cart_id;
		string cust_name;
		cout << "Whose cart?/n> ";
		cin >> cust_name;
		
		for (int i=0 ; i<custs.size() ; ++i)
		{
			if (cust_name == custs[i].cust_name)
			{
				cust_id = custs[i].cust_id;
				break;
			}
		}
		
		for (int i=0 ; i<carts.size() ; ++i)
		{
			if (cust_id == carts[i].cust_id)
			{
				cust_carts.push_back(carts[i]);
			}
		}
		
		cout 	<< "Which cart would you like to edit?\n"
				<< "Cart ID:\n";
		
		for (int i=0 ; i<cust_carts.size() ; ++i)
		{
			//RY
			//changed cust_carts[i] to cust_carts[i].display()
			//we cannot easily put an object to an output stream!
			cout << "\t" << (i+1) << ") " << cust_carts[i].display() << endl;
		}
		
		cout << "> ";
		cin >> choice;
		
		//RY changed [choice - 1] to at(choice - 1)
		//[] operator cannot included calculation inside its parameter
		cart_id = cust_carts.at(choice-1).cart_id;
		
		for (int i=0 ; i<cart_items->size() ; ++i)
		{
			if (cart_id == cart_items->at(i).cart_id)
			{
				cust_items.push_back(cart_items->at(i));
			}
		}
		
		cout << "Which item would you like to remove?\n";
		
		for (int i=0; i<cust_items.size() ; ++i)
		{
			string item_name;
			for (int j=0; j<prods.size() ; ++j)
			{
				if (cust_items[i].prod_id == prods[j].prod_id)
				{
					item_name = prods[j].prod_name;
					break;
				}
			}
			
			cout 	<< "\t" << (i + 1) << ") " 
					<< item_name
					<< "(" << cust_items[i].prod_qty << ")" << endl;
		}
		
		cout << "> ";
		cin >> choice;
		
		for (int i=0 ; i<cart_items->size() ; ++i)
		{
			if (cust_items[choice-1].cart_item_id == cart_items->at(i).cart_item_id)
			{
				cart_items->erase(cart_items->begin() + i);
			}
		}
		
		//cout << prods[].prod_name << " removed from " << cust_name << "'s cart " << cart_id;
	}
	
	static void update(vector<Cart> *carts, vector<Customer> custs) 
	{
		string cust_name= "";
		int cust_id;
		int cart_id = carts->at(carts->size()-1).cart_id + 1;
		cout << "Which customer purchased the cart?\n> ";
		cin >> cust_name;
		
		for (int i=0 ; i<custs.size() ; ++i)
		{
			if (cust_name == custs[i].cust_name)
			{
				cust_id = custs[i].cust_id;
				break;
			}
		}
		int year,day,month;
		cout << "When was the cart purchased? (e.g. '2011 27 3')\n> ";
		cin >> year
			>> day
			>> month;
		
		Date dayte(year, day, month);
		Cart crt(cart_id, cust_id, dayte);
		carts->push_back(crt);
	}	
};

#endif //OTHERSCC_H_
